# coding:utf-8

from appserver import app
from flask_script import Manager, Server, Shell, prompt_bool
from flask_migrate import MigrateCommand
from setting import *

manager = Manager(app=app)


@manager.option("-v", "--version", dest="show info and version")
def system_info():
    print("=================================================")
    print(u"项目名称:%s" % SERVER_NAME)
    print(u"项目描述:%s" % SERVER_DESCRIPTION)
    print(u"项目版本:%s" % SERVER_VERSION)
    print(u"项目版权:%s" % SERVER_COPYRIGHT)
    print("=================================================")


def make_context():
    context = {

    }
    return context


manager.add_command("shell", Shell(make_context=make_context))
manager.add_command("debug",
                    Server(use_debugger=True, use_reloader=True, host=app.config["HOST"], port=app.config["PORT"],
                           threaded=app.config["THREADED"]))
manager.add_command("runserver",
                    Server(use_debugger=False, use_reloader=False, host=app.config["HOST"], port=app.config["PORT"],
                           threaded=app.config["THREADED"]))

from models.entity.user import User
from models.entity.device_type import DeviceType
from models.entity.device import Device
from models.entity.module import Module
from models.entity.role import Role
from models.entity.organization import Organization
from models.entity.dict_category import DictCategory
from models.entity.dict import Dict
from models.entity.button import Button

# 给扩展行增加db命令, 为了数据库的迁移
manager.add_command("db", MigrateCommand)

if __name__ == "__main__":
    manager.run()
